/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import { uniq } from 'lodash';

const fillZero = num => {
  if (num < 10) {
    return `00${num}`;
  }
  if (num < 100) {
    return `0${num}`;
  }
  return num;
};

/**
 * 生成优先级
 *  */
export const createPriorities = () => {
  let num = 0;
  const options = [];
  while (num < 999) {
    num += 1;
    options.push({
      key: fillZero(num),
      value: fillZero(num),
    });
  }
  return options;
};

/**
 * 寻找最大的优先级
 *  */
export const findMinimum = (priorities = []) => {
  if (Number(priorities[0]) != 1 || priorities.length == 0) {
    return '001';
  }
  let minimum = '';

  const newArr = uniq(priorities);

  for (let i = 0; i < newArr.length; i += 1) {
    const val = newArr[i];
    if (Number(val) != i + 1) {
      minimum = i + 1;
      break;
    } else {
      minimum = newArr.length + 1;
    }
  }

  return fillZero(minimum);
};
